package com.qk.controller;

import com.qk.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    //获取所有活动列表
    @GetMapping("/activities")
    public Result listActivities(Activity  activity){
        PageResult<Activity> pageResult = activityService.listActivities(activity);
        return Result.success(pageResult);
    }
    //删除活动
    @DeleteMapping("/activities/{id}")
    public Result deleteActivity(@PathVariable Integer id){
        activityService.deleteActivity(id);
        return Result.success();
    }
    //根据id查询活动
    @GetMapping("/activities/{id}")
    public Result getActivityById(@PathVariable Integer id){
        Activity activity = activityService.getActivityById(id);
        return Result.success(activity);
    }
    //修改活动
    @PutMapping("/activities")
    public Result updateActivity(@RequestBody Activity activity){
        activityService.updateActivity(activity);
        return Result.success();
    }
    //添加活动
    @PostMapping("/activities")
    public Result addActivity(@RequestBody Activity activity){
        activityService.addActivity(activity);
        return Result.success();
    }
    //查询指定类型type的活动
    @GetMapping("/activities/type/{type}")
    public Result listActivitiesByType(@PathVariable Integer type){
        List<Activity> pageResult = activityService.listActivitiesByType(type);
        return Result.success(pageResult);
    }
}
